package kassiopeia.agent;

import kassiopeia.agent.internal.AgentIDPropertyConfigurer;
import kassiopeia.agent.plugin.PluginClassLoader;
import org.apache.log4j.Logger;
import org.springframework.context.support.GenericXmlApplicationContext;

public class KassiopeiaSpringRunner {

    private static final Logger logger = Logger.getLogger(KassiopeiaSpringRunner.class);
    public static ClassLoader sharedClassLoader;

    public static void startKassiopeiaAgent() {
        PluginClassLoader.parentClassLoader = sharedClassLoader;

        logger.info("Reading configuration files...");

        GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
        ctx.addBeanFactoryPostProcessor(new AgentIDPropertyConfigurer("kassiopeia.properties"));
        ctx.load("spring-context.xml", "spring-io.xml");
        ctx.registerShutdownHook();
        ctx.refresh();
    }
}
